import { axios } from '@/utils/request';

const api = {
  apps: 'app/list',
  app: 'app',
  status: 'app/status',
  secret: 'app/secret',
  appMore: 'app/more',
  dashboardApps: 'app/access-group',
  dashboardAppsList: 'app/access-list',
  syncData: 'app-data-sync',
  basic: 'basic-data-list'
};

/**
 * 仪表盘可见 App 分组
 */
export function readDashboardApps(params) {
  return axios({
    url: api.dashboardApps,
    params
  })
}

/**
 * 仪表盘可见 App list
 */
export function readDashboardAppsList(params) {
  return axios({
    url: api.dashboardAppsList,
    params
  })
}

/**
 * 应用分页列表
 * @param { { int pageNo, int pageSize } } params
 */
export function readApplications(params) {
  return axios({
    url: api.apps,
    params
  })
}
/**
 * 应用分页列表
 * @param { { int pageNo, int pageSize } } params
 */
export function readApplicationsHasDatatype(params) {
  return axios({
    url: 'app/appData/list',
    params
  })
}

/**
 * 新建应用
 * @param {*} params 
 */
export function createApplication(data) {
  return axios({
    url: api.app,
    method: 'post',
    data: data
  })
}

/**
 * 更新应用
 * @param {*} params 
 */
export function updateApplication(data) {
  return axios({
    url: api.app,
    method: 'put',
    data
  })
}
/**
 * 删除应用
 * @param {*} params 
 */
export function delApplication(params) {
  return axios({
    url: api.app,
    method: 'delete',
    params
  })
}
/**
 * 获取应用详情
 * @param {*} params 
 */
export function readApplication(params) {
  return axios({
    url: api.app,
    params
  })
}

/**
 * 禁用启用应用
 * @param {*} params 
 */
export function updateApplicationStatus(data) {
  return axios({
    url: api.status,
    method: 'put',
    data
  })
}

/**
 * 重置 Secret
 * @param {*} params 
 */
export function createSecret(params) {
  return axios({
    url: api.secret,
    params
  })
}

/**
 * 修改App 管理员、可见范围、secret
 * @param {*} data 
 */
export function updateeAppMore(data) {
  return axios({
    url: api.appMore,
    method: 'put',
    data
  })
}

export function getSyncData(params) {
  return axios({
    url: api.syncData,
    params,
    method: 'get'
  })
}

export function updateSyncData(data) {
  return axios({
    url: api.syncData,
    data,
    method: 'put'
  })
}

export function getRandomKey(params) {
  return axios({
    url: api.syncData + '/random',
    params,
    method: 'get'
  })
}

export function getBasicList(params) {
  return axios({
    url: api.basic,
    params
  })
}